package com.lune.job.controller;


import com.lune.job.pojo.ResPageBean;
import com.lune.job.pojo.RespBean;
import com.lune.job.pojo.Type;
import com.lune.job.service.ITypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Caiyilin
 * @since 2022-03-06
 */
@RestController
@RequestMapping("/type")
@Api(tags = "类型管理")
public class TypeController {

    @Autowired
    private ITypeService typeService;

    @ApiOperation(value = "添加类型")
    @PostMapping("/")
    public RespBean create(@RequestBody Type type){
        if (typeService.save(type)){
            return RespBean.success("添加类型成功");
        }
        return RespBean.error("添加类型失败");

    }

    @ApiOperation(value = "删除类型")
    @DeleteMapping("/")
    public RespBean delete(Integer[] ids){
        if (typeService.removeByIds(Arrays.asList(ids))){
            return RespBean.success("删除类型成功");
        }
        return RespBean.error("删除类型失败");

    }

    @ApiOperation(value = "修改类型")
    @PutMapping("/")
    public RespBean update(@RequestBody Type type){
        if (typeService.updateById(type)){
            return RespBean.success("修改类型成功");

        }
        return RespBean.error("修改类型失败");

    }

    @ApiOperation(value = "根据id查询类型")
    @GetMapping("/detail")
    public Type detail(Integer id){
        return  typeService.getById(id);
    }

    @ApiOperation(value = "分页查询类型")
    @GetMapping("/page")
    public ResPageBean getAllTypeByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        Type type){
        return typeService.getAllTypeByPage(currentPage,size,type);
    }






}
